#include "link.h"
#include "FreeRTOS.h"
#include "main.h"
 AlarmNode* phead=NULL;
extern info ttinfo;
uint8_t flag=0;
void createlist()
{

phead=pvPortMalloc(sizeof(AlarmNode));
   if(NULL==phead)
		 return ;
	 
	 phead->next=NULL;

}
void Add_alarm(uint8_t hour,uint8_t min)
{
    AlarmNode*p=phead->next;
	  while(p)
		{
		
		   if(p->AlarmType==ALARMEVENT)
			 {
			   break;
			 }
		 
			   p=p->next;
		
		}
   if(p)
	 {
	      p->hour=hour;
		    p->min=min;

	 }
	 
	 else
	 {
	    p=phead;
		  while(p->next)
			{
			  p=p->next;

			}
	 
	     AlarmNode*newnode=pvPortMalloc(sizeof(AlarmNode));
			newnode->hour=hour;
			newnode->min=min;
			p->next=newnode;
	 
	 
	 }

}
void Find_alarm(uint8_t *hour,uint8_t *min)
{

     AlarmNode*p=phead->next;
	
	while(p)
	{
	    if(p->AlarmType==ALARMEVENT)
			{
			    *hour=p->hour;
				  *min=p->min;
				  return ;
			
			
			}
	
	    p=p->next;

	}


   if(p==NULL)
	 {
	    *hour=0;
			*min=0;  
	 
	 
	 }






}
uint8_t scan_alarmstat(void)
{
    uint32_t curtime=ttinfo.time+3600*8;
    struct tm*t=localtime(&curtime);		
		
		uint8_t hour=t->tm_hour;
		uint8_t min=t->tm_min;
     if(flag==min)
		 {
		    return 0;
		 
		 
		 }
		 else
		 {flag=0;}
     AlarmNode*p=phead->next;
	  
	   while(p)
		 {
		     if(p->hour==hour&&p->min==min)
				 {   
					 
					   flag=min;
					   return 1;
				 
				 
				 
				 }
		 
		 
		   p=p->next;
		 
		 
		 
		 }


     return 0;






}
